package
{
	import flash.display.MovieClip;

	public class DroneObject
	{
		public var name:String;
		public var pos:Vector2;
		public var r:Number;
		public var dirList:Object;
		public var curDir:Number;
		public var curDirV:Vector2;
		public var goal:Vector2;
		public var speed:Number;
		public var curRot:Number = 0;
		public var isChaser:Boolean = false;
		public var ischasing:Boolean = false;
		public var waschasing:Boolean = false;
		public var ai_counter:Number = 0;
		public var ai_counter2:Number = 0;
		public var view:Vector2 = new Vector2(9, 4);
		public var fireDelayTimer:Number = 0;
		public var targ:Vector2 = new Vector2(4, 5);
		public var targ2:Vector2 = new Vector2(5, 7);
		public var targ3:Vector2 = new Vector2(3, 6);
		public var prefireDelay:Number = 0;
		public var postfireDelay:Number = 0;
		public var isFiring:Boolean = false;
		public var laserPrefireDelay:Number = 30;
		public var laserPostfireDelay:Number = 40;
		public var laserRate:Number = 80;
		public var laserTimer:Number = 0;
		public var laserLen:Number = 7;
		public var chaingunPrefireDelay:Number = 35;
		public var chaingunPostfireDelay:Number = 60;
		public var chaingunMaxNum:Number = 8;
		public var chaingunCurNum:Number = 0;
		public var chaingunRate:Number = 6;
		public var chaingunTimer:Number = 0;
		public var chaingunSpread:Number = 0.3;
		public var mc:MovieClip;
		public var eyeMC:MovieClip;
		public var snd ;
		public var UID;
		public var cell:TileMapCell;
		public var moveList:Array;
		public var beamMC:MovieClip;

		public function DroneObject()
		{
			this.name = "drone";
			this.pos = new Vector2(41, 14);
			this.r = Main.getInstance().tiles.xw * 0.75;
			this.dirList = new Object();
			this.dirList[DroneObject.AI_DIR_R] = new Vector2(1, 0);
			this.dirList[DroneObject.AI_DIR_D] = new Vector2(0, 1);
			this.dirList[DroneObject.AI_DIR_L] = new Vector2(-1, 0);
			this.dirList[DroneObject.AI_DIR_U] = new Vector2(0, -1);
			this.curDir = DroneObject.AI_DIR_R;
			this.curDirV = this.dirList[this.curDir];
			this.goal = new Vector2(54, 85);
			this.speed = Main.getInstance().tiles.xw * 0.0714285714285714;
			this.curRot = 0;
			this.isChaser = false;
			this.ischasing = false;
			this.waschasing = false;
			this.ai_counter = 0;
			this.ai_counter2 = 0;
			this.view = new Vector2(9, 4);
			this.fireDelayTimer = 0;
			this.targ = new Vector2(4, 5);
			this.targ2 = new Vector2(5, 7);
			this.targ3 = new Vector2(3, 6);
			this.prefireDelay = 0;
			this.postfireDelay = 0;
			this.isFiring = false;
			this.laserPrefireDelay = 30;
			this.laserPostfireDelay = 40;
			this.laserRate = 80;
			this.laserTimer = 0;
			this.laserLen = 7;
			this.chaingunPrefireDelay = 35;
			this.chaingunPostfireDelay = 60;
			this.chaingunMaxNum = 8;
			this.chaingunCurNum = 0;
			this.chaingunRate = 6;
			this.chaingunTimer = 0;
			this.chaingunSpread = 0.3;
			Main.getInstance().objects.Register(this);
			this.mc = Main.getInstance().gfx.CreateSprite("debugDroneMC", NinjaGraphicsSystem.LAYER_OBJECTS);
			this.mc.visible = false;
			this.eyeMC = this.mc.attachMovie("debugDroneEyeMC", "drone" + this.UID, this.UID);
			// this.snd = new Sound(this.mc);
			this.Think = this.Think2;
		}

		public var blastMC:MovieClip;
		public var gunMC:MovieClip;

		public function Destruct():void
		{
			Main.getInstance().gfx.DestroyMC(this.mc);
			Main.getInstance().gfx.DestroyMC(this.beamMC);
			Main.getInstance().gfx.DestroyMC(this.blastMC);
			Main.getInstance().gfx.DestroyMC(this.gunMC);
			Main.getInstance().gfx.DestroyMC(this.eyeMC);
			this.mc = null;
			this.beamMC = null;
			this.blastMC = null;
			this.eyeMC = null;
			this.snd = null;
		}

		public function Init(params:Array):void
		{
			var _local2 = params;
			if (_local2.length == 6)
			{
				this.pos.x = _local2[0];
				this.pos.y = _local2[1];
				this.curDir = _local2[5];
				this.SetDir(this.curDir);
				Main.getInstance().objects.AddToGrid(this);
				Main.getInstance().objects.StartUpdate(this);
				Main.getInstance().objects.Moved(this);
				this.pos.x = (this.goal.x = this.cell.pos.x);
				this.pos.y = (this.goal.y = this.cell.pos.y);
				this.SetupDroneType(_local2[2], Boolean(_local2[3]), _local2[4]);
				this.mc.scaleX = (this.mc.scaleY = 2 * this.r);
			}
		}

		public function UnInit():void
		{
			Main.getInstance().objects.RemoveFromGrid(this);
			Main.getInstance().objects.EndUpdate(this);
			Main.getInstance().objects.EndThink(this);
			Main.getInstance().objects.EndDraw(this);
		}

		public function DumpInitData():String
		{
			return "" + this.pos.x + NinjaGame.OBJPARAM_SEPERATION_CHAR + this.pos.y + NinjaGame.OBJPARAM_SEPERATION_CHAR + this.DRONEMOVE + NinjaGame.OBJPARAM_SEPERATION_CHAR + Number(this.isChaser) + NinjaGame.OBJPARAM_SEPERATION_CHAR + this.DRONEWEAP + NinjaGame.OBJPARAM_SEPERATION_CHAR + this.curDir;
		}

		public function IdleAfterDeath():void
		{
			if (this.isChaser)
			{
				this.Chase = this.Chase_NoSearch;
				this.ischasing = false;
			}
			this.Think = null;
			if (this.isFiring)
			{
				this.StopFiring();
			}
		}

		public var GetNewGoal:Function;
		public var Chase:Function;
		public var StartFiring:Function;
		public var StopFiring:Function;
		public var Update_PreFire:Function;
		public var Update_PostFire:Function;
		public var beamdx:Number;
		public var beamdy:Number;
		public var DRONEMOVE;
		public var DRONEWEAP;
		public var weaptype:int;
		public var Fire:Function;
		public var chainturretRot:Number;
		public var Update:Function;

		public function SetupDroneType(movetype, isChaser:Boolean, weaptype):void
		{
			var _local2 = movetype;
			var _local3 = weaptype;
			this.mc.clear();
			this.DRONEMOVE = _local2;
			this.DRONEWEAP = _local3;
			this.isChaser = isChaser;
			if (_local2 == DroneObject.DRONEMOVE_SURFACEFOLLOW_CW)
			{
				this.GetNewGoal = this.GetNewGoal_Simple;
				this.moveList = DroneObject.MoveList_SurfaceCW;
			}
			else if (_local2 == DroneObject.DRONEMOVE_SURFACEFOLLOW_CCW)
			{
				this.GetNewGoal = this.GetNewGoal_Simple;
				this.moveList = DroneObject.MoveList_SurfaceCCW;
			}
			else if (_local2 == DroneObject.DRONEMOVE_WANDER_CW)
			{
				this.GetNewGoal = this.GetNewGoal_Simple;
				this.moveList = DroneObject.MoveList_ChuChuCW;
			}
			else if (_local2 == DroneObject.DRONEMOVE_WANDER_CCW)
			{
				this.GetNewGoal = this.GetNewGoal_Simple;
				this.moveList = DroneObject.MoveList_ChuChuCCW;
			}
			else if (_local2 == DroneObject.DRONEMOVE_WANDER_ALTERNATING)
			{
				this.GetNewGoal = this.GetNewGoal_ChuChuAlternating;
			}
			else if (_local2 == DroneObject.DRONEMOVE_WANDER_RANDOM)
			{
				this.GetNewGoal = this.GetNewGoal_ChuChuRandom;
			}
			if (_local3 == DroneObject.DRONEWEAP_ZAP)
			{
				if (isChaser)
				{
					this.Chase = this.Chase_AxisSearch;
					this.isChaser = true;
					this.ischasing = false;
					this.mc.gotoAndStop("zapdrone_chaseidle");
				}
				else
				{
					this.Chase = this.Chase_NoSearch;
					this.isChaser = false;
					this.ischasing = false;
					this.mc.gotoAndStop("zapdrone_move");
				}
				this.name = "zap drone";
				this.weaptype = DroneObject.DRONEWEAP_ZAP;
				this.speed = this.speed * 2;
				this.TestVsPlayer = this.TestVsPlayer_Zap;
			}
			else if (_local3 == DroneObject.DRONEWEAP_LASER)
			{
				this.Chase = this.Chase_NoSearch;
				this.isChaser = false;
				this.ischasing = false;
				this.name = "laser drone";
				this.weaptype = DroneObject.DRONEWEAP_LASER;
				this.speed = this.speed * 0.5;
				this.Think = this.Think_TargetPlayer;
				this.Fire = this.Fire_Laser;
				this.StartFiring = this.StartFiring_Laser;
				this.StopFiring = this.StopFiring_Laser;
				this.Update_PreFire = this.Update_PreFire_Laser;
				this.Update_PostFire = this.Update_PostFire_Laser;
				this.prefireDelay = this.laserPrefireDelay;
				this.postfireDelay = this.laserPostfireDelay;
				Main.getInstance().objects.StartThink(this);
				this.mc.gotoAndStop("laserdrone_move");
				this.beamdx = 0;
				this.beamdy = 0;
				this.beamMC = Main.getInstance().gfx.CreateEmptySprite(NinjaGraphicsSystem.LAYER_OBJECTS);
				this.beamMC.visible = false;
				this.blastMC = Main.getInstance().gfx.CreateSprite("debugLaserBlastMC", NinjaGraphicsSystem.LAYER_OBJECTS);
				this.blastMC.visible = false;
			}
			else if (_local3 == DroneObject.DRONEWEAP_CHAINGUN)
			{
				this.Chase = this.Chase_NoSearch;
				this.isChaser = false;
				this.ischasing = false;
				this.name = "chaingun drone";
				this.weaptype = DroneObject.DRONEWEAP_CHAINGUN;
				this.speed = this.speed * 0.75;
				this.Think = this.Think_TargetPlayer;
				this.Fire = this.Fire_Chaingun;
				this.StartFiring = this.StartFiring_Chaingun;
				this.StopFiring = this.StopFiring_Chaingun;
				this.Update_PreFire = this.Update_PreFire_Chaingun;
				this.Update_PostFire = this.Update_PostFire_Chaingun;
				this.prefireDelay = this.chaingunPrefireDelay;
				this.postfireDelay = this.chaingunPostfireDelay;
				Main.getInstance().objects.StartThink(this);
				this.chainturretRot = 0;
				this.mc.gotoAndStop("chaingundrone_move");
				this.eyeMC = this.mc.attachMovie("debugChainTurretMC", "chainturret" + this.UID, this.UID);
			}
			this.Draw();
			this.mc.visible = true;
			this.Update = this.Update_Move;
			Main.getInstance().objects.StartDraw(this);
		}

		public function Draw():void
		{
			this.mc.x = this.pos.x;
			this.mc.y = this.pos.y;
			var _local2 = this.curRot - this.eyeMC.rotation;
			this.eyeMC.rotation = this.eyeMC.rotation + (0.3 * _local2);
		}

		public function Update_Move():void
		{
			this.ai_counter++;
			var dx = (this.goal.x - this.pos.x);
			var _local3 = this.goal.y - this.pos.y;
			var len2 = ((dx * dx) + (_local3 * _local3));
			if (len2 < (this.speed * this.speed))
			{
				this.pos.x = this.goal.x;
				this.pos.y = this.goal.y;
				if (this.Chase())
				{
					this.ischasing = true;
					this.mc.gotoAndPlay("zapdrone_chaseactive");
				}
				else
				{
					this.SetDir(this.GetNewGoal());
					this.ischasing = false;
				}
			}
			else
			{
				var _local2 = this.speed;
				if (this.ischasing)
				{
					_local2 = _local2 * 2;
				}
				this.pos.x = this.pos.x + (this.curDirV.x * _local2);
				this.pos.y = this.pos.y + (this.curDirV.y * _local2);
			}
			Main.getInstance().objects.Moved(this);
		}

		//
		public static const DRONEWEAP_ZAP:int = 0;
		public static const DRONEWEAP_LASER:int = 1;
		public static const DRONEWEAP_CHAINGUN:int = 2;
		//
		public static const DRONEMOVE_SURFACEFOLLOW_CW:int = 0;
		public static const DRONEMOVE_SURFACEFOLLOW_CCW:int = 1;
		public static const DRONEMOVE_WANDER_CW:int = 2;
		public static const DRONEMOVE_WANDER_CCW:int = 3;
		public static const DRONEMOVE_WANDER_ALTERNATING:int = 4;
		public static const DRONEMOVE_WANDER_RANDOM:int = 5;

		public function TestVsPlayer(guy):void
		{
		}

		public function TestVsPlayer_Zap(guy):void
		{
			var p = guy.pos;
			var _local2 = this.pos.x - p.x;
			var _local1 = this.pos.y - p.y;
			var len = Math.sqrt((_local2 * _local2) + (_local1 * _local1));
			if (len < (this.r + guy.r))
			{
				_local2 = _local2 / len;
				_local1 = _local1 / len;
				Main.getInstance().particles.SpawnZap(this.pos.x - (_local2 * this.r), this.pos.y - (_local1 * this.r), Main.getInstance().NormToRot(-_local2, -_local1));
				Main.getInstance().game.KillPlayer(NinjaGame.KILLTYPE_ELECTRIC, (-_local2) * 10, (-_local1) * 10, p.x + (guy.r * _local2), p.y + (guy.r * _local1), this);
			}
		}

		public var Think:Function;

		public function Think2():void
		{
		}

		public function Think_TargetPlayer():void
		{
			if (Main.getInstance().QueryRayObj(this.view, this.pos, PlayerObject.player.pos, PlayerObject.player))
			{
				this.StartFiring();
			}
		}

		public function StartMoving():void
		{
			Main.getInstance().objects.StartThink(this);
			this.Update = this.Update_Move;
			Main.getInstance().objects.StartDraw(this);
		}

		public function StartFiring_Laser():void
		{
			this.mc.gotoAndPlay("laserdrone_prefire");
			Main.getInstance().objects.EndThink(this);
			Main.getInstance().objects.EndDraw(this);
			this.fireDelayTimer = 0;
			this.Update = this.Update_PreFire_Laser;
			if (Main.getInstance().CollideRayvsTiles(this.targ, this.pos, this.view))
			{
			}
			this.targ2.x = this.targ.x - this.pos.x;
			this.targ2.y = this.targ.y - this.pos.y;
			this.laserLen = Math.sqrt((this.targ2.x * this.targ2.x) + (this.targ2.y * this.targ2.y));
			if (this.laserLen == 0)
			{
				this.StopFiring();
			}
			else
			{
				this.beamMC.visible = true;
				this.beamMC.clear();
				this.beamMC.lineStyle(0, 13334137, 100);
				this.beamMC.moveTo(this.pos.x, this.pos.y);
				this.beamMC.lineTo(this.targ.x, this.targ.y);
				this.beamdx = this.targ2.x / this.laserLen;
				this.beamdy = this.targ2.y / this.laserLen;
			}
		}

		public function StopFiring_Laser():void
		{
			this.snd.stop();
			this.mc.gotoAndPlay("laserdrone_postfire");
			this.beamMC.visible = false;
			this.blastMC.visible = false;
			this.blastMC.gotoAndStop(1);
			this.isFiring = false;
			this.fireDelayTimer = 0;
			this.Update = this.Update_PostFire_Laser;
		}

		public function Update_PreFire_Laser():void
		{
			Main.getInstance().particles.SpawnLaserCharge(this.pos);
			this.fireDelayTimer++;
			if (this.prefireDelay <= this.fireDelayTimer)
			{
				this.isFiring = true;
				this.Fire_Laser();
			}
		}

		public function Update_PostFire_Laser():void
		{
			this.fireDelayTimer++;
			if (this.postfireDelay <= this.fireDelayTimer)
			{
				this.StartMoving();
			}
		}

		public function Fire_Laser():void
		{
			this.mc.gotoAndStop("laserdrone_firing");
			this.beamMC.clear();
			this.beamMC.lineStyle(3, 8921634, 100);
			this.beamMC.moveTo(this.pos.x, this.pos.y);
			this.beamMC.lineTo(this.targ.x, this.targ.y);
			this.blastMC.x = this.targ.x;
			this.blastMC.y = this.targ.y;
			this.blastMC.visible = true;
			this.blastMC.scaleX = (this.blastMC.scaleY = 0);
			this.blastMC.gotoAndPlay(1);
			this.laserLen = this.laserLen * this.laserLen;
			this.laserTimer = 0;
			this.Update = this.Update_FiringLaser;
		}

		public function Update_FiringLaser():void
		{
			Main.getInstance().particles.SpawnLaserCharge(this.pos);
			var ratio = (this.laserTimer / this.laserRate);
			this.blastMC.scaleX = (this.blastMC.scaleY = 30 + (200 * ratio));
			var dx = (PlayerObject.player.pos.x - this.pos.x);
			var dy = (PlayerObject.player.pos.y - this.pos.y);
			var _local2 = (dx * this.targ2.x) + (dy * this.targ2.y);
			_local2 = _local2 / this.laserLen;
			var px;
			var _local3;
			if (_local2 < 0)
			{
				px = this.pos.x;
				_local3 = this.pos.y;
			}
			else if (_local2 < 1)
			{
				px = this.pos.x + (_local2 * this.targ2.x);
				_local3 = this.pos.y + (_local2 * this.targ2.y);
			}
			else
			{
				px = this.targ.x;
				_local3 = this.targ.y;
			}
			var tx = (px - PlayerObject.player.pos.x);
			var ty = (_local3 - PlayerObject.player.pos.y);
			if (Math.sqrt((tx * tx) + (ty * ty)) < PlayerObject.player.r)
			{
				this.StopFiring_Laser();
				var templen = Math.sqrt((this.targ2.x * this.targ2.x) + (this.targ2.y * this.targ2.y));
				Main.getInstance().game.KillPlayer(NinjaGame.KILLTYPE_LASER, 6 * (this.targ2.x / templen), 6 * (this.targ2.y / templen), px, _local3, this);
			}
			else
			{
				this.laserTimer++;
				if (this.laserRate <= this.laserTimer)
				{
					this.StopFiring();
					return;
				}
			}
		}

		public function StartFiring_Chaingun():void
		{
			this.mc.gotoAndPlay("chaingundrone_prefire");
			Main.getInstance().objects.EndThink(this);
			Main.getInstance().objects.EndDraw(this);
			this.fireDelayTimer = 0;
			this.Update = this.Update_PreFire;
		}

		public function StopFiring_Chaingun():void
		{
			this.snd.stop();
			this.mc.gotoAndPlay("chaingundrone_postfire");
			this.isFiring = false;
			this.fireDelayTimer = 0;
			this.Update = this.Update_PostFire_Chaingun;
		}

		public function Update_PreFire_Chaingun():void
		{
			var dx = (PlayerObject.player.pos.x - this.pos.x);
			var _local3 = PlayerObject.player.pos.y - this.pos.y;
			var _local2 = Main.getInstance().NormToRot(dx, _local3);
			if (180 < _local2)
			{
				_local2 = _local2 - 360;
			}
			var dr = (_local2 - this.eyeMC.rotation);
			this.eyeMC.rotation = this.eyeMC.rotation + (0.1 * dr);
			this.fireDelayTimer++;
			if (this.prefireDelay <= this.fireDelayTimer)
			{
				this.isFiring = true;
				this.Fire_Chaingun();
				this.mc.gotoAndPlay("chaingundrone_fire");
			}
		}

		public function Update_PostFire_Chaingun():void
		{
			this.fireDelayTimer++;
			if (this.postfireDelay <= this.fireDelayTimer)
			{
				this.StartMoving();
			}
		}

		public function Fire_Chaingun():void
		{
			this.chaingunTimer = 0;
			this.chaingunMaxNum = 4 + (Main.getInstance().game.GetTime() % 5);
			this.chaingunSpread = 0.1 + (0.1 * (1 + (Main.getInstance().game.GetTime() % 3)));
			this.chaingunCurNum = 0;
			this.Update = this.Update_FiringChaingun;
			var _local3 = PlayerObject.player.pos.x - this.pos.x;
			var _local2 = PlayerObject.player.pos.y - this.pos.y;
			var len = Math.sqrt((_local3 * _local3) + (_local2 * _local2));
			if (len == 0)
			{
				this.StopFiring();
			}
			else
			{
				_local3 = _local3 / len;
				_local2 = _local2 / len;
				this.targ.x = _local3;
				this.targ.y = _local2;
				var vx = (PlayerObject.player.pos.x - PlayerObject.player.oldpos.x);
				var vy = (PlayerObject.player.pos.y - PlayerObject.player.oldpos.y);
				var dp = ((vx * (-_local2)) + (vy * _local3));
				if (dp < 0)
				{
					this.targ2.x = _local2;
					this.targ2.y = -_local3;
				}
				else
				{
					this.targ2.x = -_local2;
					this.targ2.y = _local3;
				}
			}
		}

		public function Update_FiringChaingun():void
		{
			this.chaingunTimer++;
			if (this.chaingunRate <= this.chaingunTimer)
			{
				this.chaingunTimer = 0;
				if (this.chaingunMaxNum < this.chaingunCurNum)
				{
					this.StopFiring_Chaingun();
				}
				else
				{
					var i = ((this.chaingunCurNum / this.chaingunMaxNum) - 0.5);
					i = i * this.chaingunSpread;
					var sx = (this.targ.x + (i * this.targ2.x));
					var sy = (this.targ.y + (i * this.targ2.y));
					this.targ3.x = this.pos.x + sx;
					this.targ3.y = this.pos.y + sy;
					if (Main.getInstance().QueryRayObj(this.view, this.pos, this.targ3, PlayerObject.player))
					{
						this.StopFiring_Chaingun();
						Main.getInstance().game.KillPlayer(NinjaGame.KILLTYPE_SOFTBULLET, sx * 5, sy * 5, this.view.x, this.view.y, this);
					}
					var _local3 = this.view.x - this.pos.x;
					var _local2 = this.view.y - this.pos.y;
					var len = Math.sqrt((_local3 * _local3) + (_local2 * _local2));
					_local3 = _local3 / len;
					_local2 = _local2 / len;
					var rot = Main.getInstance().NormToRot(_local3, _local2);
					Main.getInstance().particles.SpawnChainBullet(this.pos, this.view, len, rot);
					this.eyeMC.rotation = rot;
					this.chaingunCurNum++;
				}
			}
		}

		//
		public static const AI_DIR_R:Number = 0;
		public static const AI_DIR_D:Number = 1;
		public static const AI_DIR_L:Number = 2;
		public static const AI_DIR_U:Number = 3;
		//
		public static const AI_ROT_0:Number = 0;
		public static const AI_ROT_90:Number = 1;
		public static const AI_ROT_180:Number = 2;
		public static const AI_ROT_270:Number = 3;
		//
		public static var MoveList_ChuChuCW:Array = [DroneObject.AI_ROT_0, DroneObject.AI_ROT_90, DroneObject.AI_ROT_270, DroneObject.AI_ROT_180];
		public static var MoveList_ChuChuCCW:Array = [DroneObject.AI_ROT_0, DroneObject.AI_ROT_270, DroneObject.AI_ROT_90, DroneObject.AI_ROT_180];
		public static var MoveList_SurfaceCW:Array = [DroneObject.AI_ROT_90, DroneObject.AI_ROT_0, DroneObject.AI_ROT_270, DroneObject.AI_ROT_180];
		public static var MoveList_SurfaceCCW:Array = [DroneObject.AI_ROT_270, DroneObject.AI_ROT_0, DroneObject.AI_ROT_90, DroneObject.AI_ROT_180];
		//
		public var dir:Number;

		public function SetDir(dir):void
		{
			var _local2 = dir;
			if (this.dir != this.curDir)
			{
				this.curDir = _local2;
				this.curDirV = this.dirList[this.curDir];
				if (_local2 < 2)
				{
					if (_local2 == 0)
					{
						this.curRot = 0;
					}
					else
					{
						this.curRot = 90;
					}
				}
				else if (_local2 == 2)
				{
					this.curRot = 180;
				}
				else
				{
					this.curRot = -90;
				}
			}
		}

		public function TestEdge(dir):Boolean
		{
			var _local2;
			var _local3;
			if (dir == DroneObject.AI_DIR_U)
			{
				_local2 = this.cell.eU;
				_local3 = this.cell.nU;
			}
			else if (dir == DroneObject.AI_DIR_L)
			{
				_local2 = this.cell.eL;
				_local3 = this.cell.nL;
			}
			else if (dir == DroneObject.AI_DIR_D)
			{
				_local2 = this.cell.eD;
				_local3 = this.cell.nD;
			}
			else if (dir == DroneObject.AI_DIR_R)
			{
				_local2 = this.cell.eR;
				_local3 = this.cell.nR;
			}
			else
			{
				return(false);
			}
			if (_local2 == TileMapCell.EID_OFF)
			{
				this.goal.x = _local3.pos.x;
				this.goal.y = _local3.pos.y;
				return(true);
			}
			return(false);
			return(_local3);
		}

		public function Chase_NoSearch():Boolean
		{
			return false;
		}

		public var surfaceFutureDir;

		public function Chase_SurfaceGrab():Boolean
		{
			this.Chase = this.Chase_AxisSearch;
			this.SetDir(this.surfaceFutureDir);
			return(false);
		}

		public function Chase_AxisSearch():Boolean
		{
			var di = (PlayerObject.player.cell.i - this.cell.i);
			var _local3 = PlayerObject.player.cell.j - this.cell.j;
			var _local2;
			var t;
			if (Math.abs(di) < 1)
			{
				t = Math.abs(_local3);
				if (PlayerObject.player.pos.y < this.pos.y)
				{
					if (this.curDir == DroneObject.AI_DIR_D)
					{
						return(false);
					}
					else
					{
						_local2 = DroneObject.AI_DIR_U;
					}
				}
				else if (this.curDir == DroneObject.AI_DIR_U)
				{
					return(false);
				}
				else
				{
					_local2 = DroneObject.AI_DIR_D;
				}
			}
			else if (Math.abs(_local3) < 1)
			{
				t = Math.abs(di);
				if (PlayerObject.player.pos.x < this.pos.x)
				{
					if (this.curDir == DroneObject.AI_DIR_R)
					{
						return(false);
					}
					else
					{
						_local2 = DroneObject.AI_DIR_L;
					}
				}
				else if (this.curDir == DroneObject.AI_DIR_L)
				{
					return(false);
				}
				else
				{
					_local2 = DroneObject.AI_DIR_R;
				}
			}
			else
			{
				return(false);
			}
			if (this.FindTarget(_local2, t))
			{
				this.SetDir(_local2);
				if (this.DRONEMOVE < DroneObject.DRONEMOVE_WANDER_CW)
				{
					var rot;
					this.Chase = this.Chase_SurfaceGrab;
					if (this.DRONEMOVE == DroneObject.DRONEMOVE_SURFACEFOLLOW_CW)
					{
						rot = DroneObject.AI_ROT_270;
					}
					else if (this.DRONEMOVE == DroneObject.DRONEMOVE_SURFACEFOLLOW_CCW)
					{
						rot = DroneObject.AI_ROT_90;
					}
					else
					{
						return(false);
					}
					this.surfaceFutureDir = Main.getInstance().RotateAIDir(_local2, rot);
				}
				return(true);
			}
			return(false);
			return(_local3);
		}

		public function FindTarget(dir, t):Boolean
		{
			var _local3 = t;
			var _local2 = 0;
			var _local1 = this.cell;
			if (dir < 2)
			{
				if (dir == DroneObject.AI_DIR_R)
				{
					while (_local2 < _local3)
					{
						_local2++;
						if (_local1.eR == TileMapCell.EID_OFF)
						{
							_local1 = _local1.nR;
						}
						else
						{
							return(false);
						}
					}
					while (_local1.eR == TileMapCell.EID_OFF)
					{
						_local2++;
						_local1 = _local1.nR;
					}
					this.goal.x = this.cell.pos.x + (_local2 * (2 * this.cell.xw));
					return(true);
				}
				if (dir == DroneObject.AI_DIR_D)
				{
					while (_local2 < _local3)
					{
						_local2++;
						if (_local1.eD == TileMapCell.EID_OFF)
						{
							_local1 = _local1.nD;
						}
						else
						{
							return(false);
						}
					}
					while (_local1.eD == TileMapCell.EID_OFF)
					{
						_local2++;
						_local1 = _local1.nD;
					}
					this.goal.y = this.cell.pos.y + (_local2 * (2 * this.cell.yw));
					return(true);
				}
				return(false);
			}
			if (dir == DroneObject.AI_DIR_L)
			{
				while (_local2 < _local3)
				{
					_local2++;
					if (_local1.eL == TileMapCell.EID_OFF)
					{
						_local1 = _local1.nL;
					}
					else
					{
						return(false);
					}
				}
				while (_local1.eL == TileMapCell.EID_OFF)
				{
					_local2++;
					_local1 = _local1.nL;
				}
				this.goal.x = this.cell.pos.x - (_local2 * (2 * this.cell.xw));
				return(true);
			}
			if (dir == DroneObject.AI_DIR_U)
			{
				while (_local2 < _local3)
				{
					_local2++;
					if (_local1.eU == TileMapCell.EID_OFF)
					{
						_local1 = _local1.nU;
					}
					else
					{
						return(false);
					}
				}
				while (_local1.eU == TileMapCell.EID_OFF)
				{
					_local2++;
					_local1 = _local1.nU;
				}
				this.goal.y = this.cell.pos.y - (_local2 * (2 * this.cell.yw));
				return(true);
			}
			return(false);
			return(_local3);
		}

		public function GetNewGoal_Simple():Number
		{
			var _local2 = this.moveList;
			var _local3 = this.curDir;
			var _local1 = Main.getInstance().RotateAIDir(_local3, _local2[0]);
			if (this.TestEdge(_local1))
			{
				return(_local1);
			}
			else
			{
				_local1 = Main.getInstance().RotateAIDir(_local3, _local2[1]);
				if (this.TestEdge(_local1))
				{
					return(_local1);
				}
				else
				{
					_local1 = Main.getInstance().RotateAIDir(_local3, _local2[2]);
					if (this.TestEdge(_local1))
					{
						return(_local1);
					}
					else
					{
						_local1 = Main.getInstance().RotateAIDir(_local3, _local2[3]);
						if (this.TestEdge(_local1))
						{
							return(_local1);
							return(undefined);
						}
					}
				}
			}
			return(undefined);
		}

		public function GetNewGoal_ChuChuAlternating()
		{
			if (this.ai_counter2 == 0)
			{
				this.moveList = DroneObject.MoveList_ChuChuCW;
				var _local2 = this.GetNewGoal_Simple();
				if (_local2 == this.curDir)
				{
				}
				else
				{
					this.ai_counter2 = 1;
				}
				return(_local2);
			}
			this.moveList = DroneObject.MoveList_ChuChuCCW;
			var _local2 = this.GetNewGoal_Simple();
			if (_local2 == this.curDir)
			{
			}
			else
			{
				this.ai_counter2 = 0;
			}
			return(_local2);
		}

		public function GetNewGoal_ChuChuRandom()
		{
			if ((this.ai_counter % 2) == 0)
			{
				this.moveList = DroneObject.MoveList_ChuChuCW;
				var _local2 = this.GetNewGoal_Simple();
				if (_local2 == this.curDir)
				{
				}
				else
				{
					this.ai_counter = 1;
				}
				return(_local2);
			}
			this.moveList = DroneObject.MoveList_ChuChuCCW;
			var _local2 = this.GetNewGoal_Simple();
			if (_local2 == this.curDir)
			{
			}
			else
			{
				this.ai_counter = 0;
			}
			return(_local2);
			return(_local2);
		}
	}
}